package com.example.NearByLocation;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2014/11/25.
 */
public class ThirdActivity extends Activity {
    private  Button       back_toSecond_bt;
    private  List<String> list;
    private  List<String> tList;
    private  List<String> thirdList;
    private  Data3List    data3List;
    private  ListView thirdlist_listview;
    private  TextView thirdMenu_textview;
    private TextView classify_TextView;
    private Button classify_Button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.thirdmenu);

        data3List=new Data3List();
        back_toSecond_bt= (Button) findViewById(R.id.back_toSecond_bt);
        back_toSecond_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        SharedPreferences pref2=getSharedPreferences("ServiceName", MODE_PRIVATE);
        String firstName=pref2.getString("firstName","aa");
        SharedPreferences pref=getSharedPreferences("ServiceName", MODE_PRIVATE);
        String secondName=pref.getString("secondName", "aa");

        thirdMenu_textview=(TextView)findViewById(R.id.thirdMenu_textview);
        thirdMenu_textview.setText(secondName);

        thirdList=new ArrayList<String>();
        thirdList=searchFirstName(firstName,secondName);
        ThirdAdapter thirdAdapter=new ThirdAdapter(thirdList,R.layout.list_item,this);
        thirdlist_listview=(ListView)  findViewById(R.id.thirdlist_listview);
        thirdlist_listview.setAdapter(thirdAdapter);

    }
    private List<String> searchFirstName(String firstName,String secondName){
        tList=new ArrayList<String>();
        if(firstName.equals("餐饮服务")){
            tList= searchCateringList(secondName);
        }else if(firstName.equals("购物服务")){
            tList=searchShoppingList(secondName);
        }
        else if(firstName.equals("生活服务")){
            tList=searchLifeServiceList(secondName);
        }
        else if(firstName.equals("体育休闲服务")){
            tList=searchSportingList(secondName);
        }
        else if(firstName.equals("住宿服务")){
            tList=searchResidentialList(secondName);
        }
        else if(firstName.equals("医疗保健服务")){
            tList=searchHealthCareList(secondName);
        }
        else if(firstName.equals("科教文化服务")){
            tList=searchS_EduList(secondName);
        }
        else if(firstName.equals("交通设施服务")){
            tList=searchTrafficeList(secondName);
        }
        return tList;
    }
    private List<String> searchCateringList(String str){
        list=new ArrayList<String>();
        if(str.equals("中餐厅")){
            list=data3List.getCatering3_China();
        }else if(str.equals("外国餐厅")){
            list=data3List.getCatering3__Foreign();
        }
        else if(str.equals("快餐厅")){
            list=data3List.getCatering3_Fast();
        }
        else if(str.equals("休闲餐饮场所")){
            list=data3List.getCatering3_Relax();
        }
        else if(str.equals("咖啡厅")){
            list=data3List.getCatering3_Coffee();
        }
        else if(str.equals("茶艺馆")){
            list=data3List.getCatering3_Tea();
        }
        else if(str.equals("冷饮店")){
            list=data3List.getCatering3_Cooler();
        }
        else if(str.equals("糕饼店")){
            list=data3List.getCatering3_Cake();
        }
        else if(str.equals("甜品店")){
            list=data3List.getCatering3_Sweetmeats();
        }
        return list;
    }
    private List<String> searchShoppingList(String str){
        list=new ArrayList<String>();
        if(str.equals("商场")){
            list=data3List.getShopping3_Market();
        }else if(str.equals("便民商店／便利店")){
            list=data3List.getShopping3_DimeStore();
        }
        else if(str.equals("家电电子卖场")){
            list=data3List.getShopping3_HouseAp();
        }
        else if(str.equals("花鸟鱼虫市场")){
            list=data3List.getShopping3_AnimalMarket();
        }
        else if(str.equals("家居建材市场")){
            list=data3List.getShopping3_HouseBuMarket();
        }
        else if(str.equals("综合市场")){
            list=data3List.getShopping3_CompositeMarket();
        }
        else if(str.equals("文化用品店")){
            list=data3List.getShopping3_CulturalGoods();
        }
        else if(str.equals("体育用品店")){
            list=data3List.getShopping3_SportGoods();
        } else if(str.equals("超级市场")){
            list=data3List.getShopping3_SuperMarket();
        }
        return list;
    }
    private List<String> searchLifeServiceList(String str){
        list=new ArrayList<String>();
        if(str.equals("旅行社")){
            list=data3List.getLifeService3_TravalAg();
        }else if(str.equals("信息咨询中心")){
            list=data3List.getLifeService3_InforCenter();
        }
        else if(str.equals("售票处")){
            list=data3List.getLifeService3_TicketSale();
        }
        else if(str.equals("邮局")){
            list=data3List.getLifeService3_PostOf();
        }
        else if(str.equals("物流速递")){
            list=data3List.getLifeService3_Logistics();
        }
        else if(str.equals("电讯营业厅")){
            list=data3List.getLifeService3_Telecom();
        }
        else if(str.equals("事务所")){
            list=data3List.getLifeService3_Office();
        }
        else if(str.equals("人才市场")){
            list=data3List.getLifeService3_TalentMarket();
        } else if(str.equals("自来水营业厅")){
            list=data3List.getLifeService3_TapWater();
        }
        return list;
    }
    private List<String> searchSportingList(String str){
        list=new ArrayList<String>();
        if(str.equals("运动场馆")){
            list=data3List.getSporting3_SportsBu();
        }else if(str.equals("高尔夫相关")){
            list=data3List.getSporting3_Golf();
        }
        else if(str.equals("娱乐场所")){
            list=data3List.getSporting3_Amusement();
        }
        else if(str.equals("度假疗养场所")){
            list=data3List.getSporting3_SpaPlaces();
        }
        else if(str.equals("休闲场所")){
            list=data3List.getSporting3_Leisure();
        }
        else if(str.equals("影剧院")){
            list=data3List.getSporting3_Movie();
        }

        return list;
    }
    private List<String> searchResidentialList(String str){
        list=new ArrayList<String>();
        if(str.equals("宾馆酒店")){
            list=data3List.getResiData3_Hotel();
        }else if(str.equals("旅馆招待所")){
            list=data3List.getResiData3_GuestHouse();
        }

        return list;
    }
    private List<String> searchHealthCareList(String str){
        list=new ArrayList<String>();
        if(str.equals("综合医院")){
            list=data3List.getHealthData3_GeneHospital();
        }else if(str.equals("专科医院")){
            list=data3List.getHealthData3_SpecialH();
        }
        else if(str.equals("诊所")){
            list=data3List.getHealthData3_Clinic();
        }
        else if(str.equals("急救中心")){
            list=data3List.getHealthData3_EmergencyC();
        }
        else if(str.equals("疾病预防机构")){
            list=data3List.getHealthData3_DiseaseP();
        }
        else if(str.equals("医药保健相关")){
            list=data3List.getHealthData3_Medicine();
        }
        else if(str.equals("动物医疗场所")){
            list=data3List.getHealthData3_AnimalP();
        }

        return list;
    }
    private List<String> searchS_EduList(String str){
        list=new ArrayList<String>();
        if(str.equals("博物馆")){
            list=data3List.getS_EduData3_Museum();
        }else if(str.equals("展览馆")){
            list=data3List.getS_EduData3_Exhibition();
        }
        else if(str.equals("会展中心")){
            list=data3List.getS_EduData3_ConventionC();
        }
        else if(str.equals("美术馆")){
            list=data3List.getS_EduData3_Gallery();
        }
        else if(str.equals("图书馆")){
            list=data3List.getS_EduData3_Library();
        }
        else if(str.equals("科技馆")){
            list=data3List.getS_EduData3_Science();
        }
        else if(str.equals("天文馆")){
            list=data3List.getS_EduData3_Planetarium();
        }
        else if(str.equals("文化宫")){
            list=data3List.getS_EduData3_CulturalP();
        } else if(str.equals("档案馆")){
            list=data3List.getS_EduData3_Archives();
        }
        return list;
    }
    private List<String> searchTrafficeList(String str){
        list=new ArrayList<String>();
        if(str.equals("飞机场")){
            list=data3List.getTrafData3_Airport();
        }else if(str.equals("火车站")){
            list=data3List.getTrafData3_Railway();
        }
        else if(str.equals("港口码头")){
            list=data3List.getTrafData3_Port();
        }
        else if(str.equals("长途汽车站")){
            list=data3List.getTrafData3_LongDistance();
        }
        else if(str.equals("地铁站")){
            list=data3List.getTrafData3_Subway();
        }
        else if(str.equals("轻轨站")){
            list=data3List.getTrafData3_Lightway();
        }
        else if(str.equals("公交车站")){
            list=data3List.getTrafData3_Bus();
        }
        else if(str.equals("班车站")){
            list=data3List.getTrafData3_RegularB();
        } else if(str.equals("停车场")){
            list=data3List.getTrafData3_Parking();
        }
        else if(str.equals("过境口岸")){
            list=data3List.getTrafData3_TransitPort();
        }
        return list;
    }
    class  ThirdAdapter extends ListAdapter{
        ThirdAdapter(List<String> list, int resource, Context context) {
            super(list, resource, context);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view= super.getView(position, convertView, parent);
            classify_TextView=(TextView)view.findViewById(R.id.classify_TextView);
            classify_Button=(Button)view.findViewById(R.id.classify_Button);
            final   String serviceName=  classify_TextView.getText().toString();
            classify_Button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    secondJump(serviceName);
                }
            });
            classify_TextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(ThirdActivity.this,PoiListActivity.class);
                    SharedPreferences.Editor editor=getSharedPreferences("ServiceName",MODE_PRIVATE).edit();
                    editor.putString("thirdName",serviceName);
                    editor.commit();
                    startActivity(intent);
                }
            });
            return view;
        }
        private void  secondJump(String serviceName){
            SharedPreferences.Editor editor=getSharedPreferences("ServiceName",MODE_PRIVATE).edit();
            editor.putString("thirdName",serviceName);
            editor.commit();
            Intent intent =new Intent(ThirdActivity.this,PoiListActivity.class);
            startActivity(intent);
        }
    }
}
